package com.yunji.base.business;

import com.yunji.base.cache.BaseCache;
import com.yunji.base.domain.BelongDO;
import com.yunji.base.dto.ManagerDTO;
import com.yunji.base.service.ManagerService;
import com.yunji.base.service.SiteService;
import com.yunji.common.base.BaseBusiness;
import com.yunji.common.model.domain.SiteDO;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.system.service.TokenService;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.user.business
 * @FileName SiteUserBusiness.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-05-29 17:06:40
 * @Description 网点用户业务处理
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-05-29 17:06:40		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Component
public class MangerBusiness extends BaseBusiness {
    @Resource
    TokenService tokenService;

    @Resource
    SiteService siteService;


    @Resource
    ManagerService managerService;

    public ManagerDTO currentSite() {
        LoginInfo user = tokenService.getUser();
        Long belongId = user.getBelongId();
        logs.info("【网点信息】当前用户所属ID：{}", belongId);
        BelongDO belong = BaseCache.getBelong(belongId);
        Assert.isTrue(BeanUtils.isNotNull(belong), "未找到网点信息");
        Long siteId = belong.getSiteId();
        logs.info("【网点信息】当前用户网点ID：{}", siteId);
        SiteDO site = siteService.getById(siteId);
        Assert.isTrue(BeanUtils.isNotNull(site), "未找到网点信息");
        ManagerDTO dto = new ManagerDTO();
        BeanUtils.clone(belong,dto);
        BeanUtils.clone(site, dto);
        return dto;
    }

    public ManagerDTO getSiteInfo(Long managerId) {
        return managerService.selectManagerUser(managerId);
    }
}